package com.culture.java.online.education.platform.business.demo.controller;

import com.culture.java.online.education.platform.common.base.exception.CustomServiceException;
import com.culture.java.online.education.platform.common.base.response.Code;
import com.culture.java.online.education.platform.common.base.response.R;
import com.culture.java.online.education.platform.data.demo.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping("demo")
@Slf4j
@Validated
public class DemoController {

    @Value("${environment.name}")
    private String environmentName;

//    private static Logger logger = LoggerFactory.getLogger(DemoController.class);

    @GetMapping("test")
    public R test(String version) {
//        logger.debug("DEBUG级别日志");
//        logger.info("INFO级别日志");
//        logger.warn("WARN级别日志");
//        logger.error("ERROR级别日志");

        log.debug("接收到的版本 - {}，环境配置 - {}", version, environmentName);

        log.debug("DEBUG级别日志");
        log.info("INFO级别日志");
        log.warn("WARN级别日志");
        log.error("ERROR级别日志");
        System.out.println("DemoController.test");
//        throw new CustomServiceException(Code.PARAM_VALIDATE_ERROR);

//        System.out.println(1/0);
        return R.success("[demo test] - " + System.currentTimeMillis());
    }

    @PostMapping("save")
    public R save(@Valid Student student) {
        log.debug("保存的学生对象 - {}", student);
        return R.success(student);
    }

    @GetMapping("get")
    public R get(@NotBlank(message = "用户名不能为空！") String username, @NotBlank(message = "密码不能为空！") String password) {
        log.debug("接收的形参 用户名 - {}，密码 - {}", username, password);
        return R.success();
    }

}
